<template>
  <div>
    <el-form ref="form" :inline="true" :model="searchObj" label-width="80px">
      <el-form-item label="手机号">
        <el-input v-model="searchObj.mobile"></el-input>
      </el-form-item>
      <el-form-item label="会员类型">
        <el-select v-model="searchObj.userType" placeholder="请选择会员类型">
          <el-option label="投资人" value="1"></el-option>
          <el-option label="借款人" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-left: 20px">
        <el-button type="primary" @click="fetchData()">搜索</el-button>
      </el-form-item>
      <el-form-item style="margin-left: 20px">
        <el-button type="info" plain @click="clearPage">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table border :data="list" style="width: 100%">
      <el-table-column label="序号" align="center" width="80">
        <template slot-scope="{ $index }">
          {{ (page - 1) * limit + $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="用户类型" align="center">
        <template slot-scope="{ row }">
          <el-tag type="success" v-if="row.userType == 1">投资人</el-tag>
          <el-tag v-else>借款人</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="mobile" label="手机号"></el-table-column>
      <el-table-column prop="name" label="用户姓名"></el-table-column>
      <el-table-column prop="mobile" label="身份证号码"></el-table-column>
      <el-table-column prop="integral" label="用户积分"></el-table-column>
      <el-table-column prop="createTime" label="注册时间"></el-table-column>
      <el-table-column prop="bindStatus" label="绑定状态" align="center">
        <template slot-scope="{ row }">
          <el-tag type="success" v-if="row.bindStatus == 1">已绑定</el-tag>
          <el-tag v-else>未绑定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="用户状态" align="center">
        <template slot-scope="{ row }">
          <el-tag
            type="success"
            v-if="row.status == 1"
            @click="lockOrUnlock(row)"
          >
            正常
          </el-tag>
          <el-tag type="warning" v-else>锁定</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="{ row }">
          <el-button
            type="warning"
            v-if="row.status == 1"
            @click="lockOrUnlock(row)"
          >
            锁定
          </el-button>
          <el-button
            type="success"
            v-if="row.status == 0"
            @click="lockOrUnlock(row)"
          >
            解锁
          </el-button>
          <el-button type="success" @click="getRecord(row)">登录日志</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      align="center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[3, 5, 7, 9]"
      :page-size="limit"
      layout=" prev, pager, next,->,jumper,total, sizes"
      :total="total"
    ></el-pagination>
    <el-dialog title="登录日志" :visible.sync="dialogTableVisible">
      <el-table :data="LoginRecordList">
        <el-table-column
          label="序号"
          width="80"
          type="index"
        ></el-table-column>
        <el-table-column
          property="ip"
          label="ip"
        
        ></el-table-column>
        <el-table-column property="createTime" label="登录时间" ></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      total: 0,
      page: 1,
      limit: 3,
      searchObj: {},
      LoginRecordList: [],
      dialogTableVisible: false,
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    async getRecord(row){
      this.dialogTableVisible = true
      const result = await this.$API.userInfo.getRecord(row.id)
      this.LoginRecordList = result.data.loginRecords
    },
    async lockOrUnlock(obj){
      const lockOrUnLock ={id:obj.id,status:obj.status}
      await this.$API.userInfo.lockOrUnLock(lockOrUnLock)
      this.fetchData()


    },
    clearPage(){
      this.searchObj = {}
      this.fetchData()
    },
    handleSizeChange(size){
      this.limit = size
      this.fetchData()
    },
    handleCurrentChange(pager){
      this.page = pager;
      this.fetchData(pager)
    },

    async fetchData(page = 1) {
      this.page = page
      const result = await this.$API.userInfo.userInfoPage(
        this.page,
        this.limit,
        this.searchObj
      )
      this.list = result.data.page.records
      this.total = result.data.page.total
    },
  },
}
</script>

<style></style>
